<template>
  <div class="right-container">
    <div class="screen-container">
      <!-- 搜索框 -->
      <search-form
        :data="queryParams"
        :field-list="filterInfo.fieldList"
        @handleSearch="handleQuery"
        @handleReset="resetQuery"
      />
    </div>
    <el-row :gutter="10">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增
        </el-button
        >
      </el-col>
    </el-row>
    <HkTable
      :loading="loading"
      :tableData="tableList"
      :tableColumns="tableFieldList"
      :showPag="true"
      :isNeedIndex="true"
      :queryParams="queryParams"
      rowkey="id"
      :total="total"
      @changePage="changePage"
    >
      <template #metricsName="scope">
        <el-button type="text" @click="handleEdit(scope.row)">{{ scope.row.row.metricsName }}</el-button>
      </template>
      <template #normalCode="scope">
          <span class="Inspan"
                :class="
                scope.row.row.normalCode == 3
                  ? 'simple'
                  : scope.row.row.normalCode == 2
                  ? 'big'
                  : scope.row.row.normalCode == 1
                  ? 'major'
                  : 'serious'
              "
          >{{ scope.row.row.normalCode == 0 ? '特别重大' : scope.row.row.normalCode == 1 ? '重大' : scope.row.row.normalCode == 2 ? '较大' :scope.row.row.normalCode == 3? '一般' :''}}</span>
      </template>
    </HkTable>
    <diaForm ref="dialogRef" title="新增" @handleSubmit="getList"></diaForm>
  </div>
</template>

<script>
import SearchForm from '@/components/HkSearchform'
import DiaForm from '../Common/DiaForm.vue'
import { getMetricsBaseList } from '@/api/analysis/monitoring'
import HkTable from '@/components/HKTable'

export default {
  components: { DiaForm, SearchForm, HkTable },
  props: {
    checkList: {
      type: Array,
      default: []
    }
  },
  data() {
    return {
      // 新增框是否 可见
      open: false,
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 弹出层标题
      title: '',
      // 查询参数
      queryParams: {
        metricsName: '',
        size: 10,
        current: 1,
        tags: []
      },
      // 查询
      filterInfo: {
        fieldList: [
          { label: '关键字', type: 'input', field: 'metricsName' }
        ]
      },
      tableList: [],
      tableFieldList: [
        { label: '事件名称', param: 'metricsName', type: 'slot' },
        { label: '事件级别', param: 'normalCode', type: 'slot' },
        { label: '标识符', param: 'metricsCode' },
        { label: '事件分类', param: 'eventType' }

        /*  { label: '是否发送工单', param: 'orderFlag' },
          { label: '是否发送邮件', param: 'emailFlag' },*/
      ]
    }
  },
  created() {
    this.getList()
  },

  methods: {
    /** 查询角色列表 */
    getList() {
      this.loading = true
      getMetricsBaseList(this.queryParams).then(res => {
        this.tableList = res.list
        this.total = res.total
        this.loading = false
      })

    },
    /** 搜索按钮操作 */
    handleQuery(value) {
      this.queryParams.metricsName = value.metricsName
      this.getList()
    },
    /** 重置按钮*/
    resetQuery() {
      this.queryParams.metricsName = undefined
      this.getList()
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$refs.dialogRef.show()
    },
    /** 分页*/
    changePage(value) {
      this.getList()
    },
    /** 编辑事件名称*/
    handleEdit(data) {
      this.$router.push({
        path: '/kpiDetail',
        query: {
          metricsBaseCode: data.row.metricsCode,
        }
      })
    }
  },
  watch: {
    checkList(newValue, oldValue) {
      this.queryParams.tags = newValue
      this.getList()
    }
  }

}
</script>
<style lang="scss" scoped>
.app-container {
  padding: 0;
}

.iconi {
  width: 16px;
  height: 16px;
  display: inline-block;
  text-align: center;
  border-radius: 50%;
  margin-right: 10px;
  line-height: 16px;
  color: white;

  &::before {
    font-size: 10px;
    font-weight: 600;
  }
}
</style>
